package com.ruyuan.eshop.framework.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * <p>
 * 用户信息上下文
 * </p>
 *
 * @author pwd
 * @version 1.0
 */
public class LoginUserContext {

    /**
     * 登录用户信息
     */
    private static final ThreadLocal<LoginUser> LOGIN_USER = new TransmittableThreadLocal<>();

    public static void setLoginUser(LoginUser loginUser) {
        LOGIN_USER.set(loginUser);
    }

    public static LoginUser getLoginUser() {
        return LOGIN_USER.get();
    }

    /**
     * 令牌
     */
    private static final ThreadLocal<String> TOKEN = new TransmittableThreadLocal<>();

    public static void setToken(String token) {
        TOKEN.set(token);
    }

    public static String getToken() {
        return TOKEN.get();
    }

    /**
     * 清空上下文信息
     */
    public static void clear() {
        LOGIN_USER.remove();
        TOKEN.remove();
    }

}